
import {
    getAccessToken
} from '~/api/getAccessToken'


const state = () => ({
    name: '我是api模块',
    client_id: `${import.meta.env.VITE_BAIDUAI_KEY}`,
    client_secret: `${import.meta.env.VITE_BAIDUAI_SECRET}`,
    ACCESS_TOKEN: ''
})
const mutations = {
    SET_ACCESS_TOKEN(state, ACCESS_TOKEN) {
        state.ACCESS_TOKEN = ACCESS_TOKEN
    }
}

const actions = {
    //获取到ACCESS_TOKEN
    async getAccessToken({ commit, state }) {
        const client_id = state.client_id
        const client_secret = state.client_secret
        const body = {
            client_id,
            client_secret
        }
        try {
            await getAccessToken(body).then(res => {
                console.log(res)
                console.log('获取baiduai的access_token成功')
            }).catch(err => {
                throw err
            })
        } catch (err) {
            console.log(err)
        }
    },
}
export default {
    namespaced: true,
    state,
    actions,
    mutations,
}
